<template>
  <div class="liuyan">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="articleId.articles" label="商品名" width="120">
        <el-table-column label="商品 ID" prop="articleId._id" align="center">
        </el-table-column>
      </el-table-column>
      <el-table-column prop="userId.nickName" label="用户名" width="120">
      </el-table-column>
      <el-table-column prop="time" label="留言日期" width="150">
      </el-table-column>
      <el-table-column prop="content" label="留言内容" width="360">
      </el-table-column>
      <el-table-column prop="caozuo" label="操作" width="120">
        <template slot-scope="scope">
          <!-- 删除 -->
          <el-button
            @click="deleteRow(scope.$index, scope.row)"
            type="text"
            size="small"
            class="el-icon-delete"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import messageApi from "../../api/message.js";

export default {
  data() {
    return {
      tableData: [],
    };
  },
  //调用获取留言
  created() {
    this.get();
  },
  methods: {
    //删除单条留言
    deleteRow(index, row) {
      console.log(index, row);
      messageApi.delete(row._id);
      messageApi.getAll().then((res) => {
        this.tableData = res;
      });
      this.$message("删除成功");
    },
    //获取留言
    get() {
      messageApi.getAll().then((res) => {
        this.tableData = res;
        console.log(res);
      });
    },
  },
};
</script>

<style></style>
